package cdu.javaendwork.Controller.Admin.AdoptionMore;

import cdu.javaendwork.model.sqlModel.Post;
import cdu.javaendwork.service.Impl.AdoptionMore.PostServiceImpl;
import cdu.javaendwork.service.Interface.AdoptionMore.PostService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/post_ban")
public class PostBanController extends HttpServlet {
    PostService postService = new PostServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pid = req.getParameter("postid");
        int postid = Integer.parseInt(pid);

        Post post = postService.findByid(postid);
        int status = post.getStatus();

        if(status == 1)
        {
            postService.update(postid, post.getUserid(), post.getPetid(), 2, post.getTitle()
                    , post.getContent(), post.getDate()
            );
        }else
        {
            postService.update(postid, post.getUserid(), post.getPetid(), 1, post.getTitle()
                    , post.getContent(), post.getDate()
            );
        }

        req.getRequestDispatcher("post_list").forward(req,resp);
    }
}
